﻿using System.Text;
using System.Collections.Generic;
using FarseerGames.FarseerPhysics;
using FarseerGames.FarseerPhysics.Collisions;
using FarseerGames.FarseerPhysics.Dynamics.Springs;
using FarseerGames.FarseerPhysics.Factories;
using PhysicsObjects;
using PrototypeGame.ScreenSystem;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Content;
using UnitLibrary.Managers;
using UnitLibrary.GameObjects.Physics; using UnitLibrary.GameObjects.Units;
using UnitLibrary.Utility;

namespace PrototypeGame.GameScreens
{
    public class LevelOneScreen: MainGameScreen
    {
        
        public LevelOneScreen(Game game)
            : base(game)
        {
            _gameLevel = 1;
        }

        private PointsManager _killPointsManager;

        /// <summary>
        /// 
        /// </summary>
        public override void Initialize()
        {           
            base.Initialize();
        }

        public override void LoadContent()
        {       
            _gameComponents.CreateComponents();
            
            _killPointsManager = new PointsManager(this._game, _gameComponents);
            //_game.Components.Add(_killPointsManager);
            //todo: rethink this:
            //foreach (RPool<GameUnit<EnemyI, MovablePhyObj>>.Node node in _gameComponents.enemyManager.UnitPool.AllNodes)
            //{
            //    node.isRemoved += EnemyRemoved;
            //}
            base.LoadContent();
        }

        public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen)
        {
            GameWinConditions();
            GameLoseConditions();
            
            base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);
        }

        /// <summary>
        /// Conditions for a win
        /// </summary>
        public override void GameWinConditions()
        {
            if (_killPointsManager.Points > 10)
                EndGame(GameState.PlayerWonByPoints);
            base.GameWinConditions();
        }

        /// <summary>
        /// Conditions for a lose
        /// </summary>
        public override void GameLoseConditions()
        {            
            base.GameLoseConditions();
        }

        /// <summary>
        /// Get the level title
        /// </summary>
        /// <returns></returns>
        public static string GetLevelTitle()
        {
            return "Level one, dominate 30 enemies";
        }        

        public static string GetLevelDetails()
        {
            StringBuilder sb = new StringBuilder();
            sb.AppendLine("Score points by killing the enemies!");
            sb.AppendLine("To beat this mission, you must kill 30 enemies");
            return sb.ToString();
        }
    }
}
